<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>函数求和</title>
	</head>
	<body>

		<p>
			<input id="btn" type="button" value="求和" onclick="sum()"/>
			<input id="btn" type="button" value="反转" onclick="reversal()"/>
			<input id="btn" type="button" value="包含" onclick="contain()"/>
				<input id="btn" type="button" value="添加" onclick="add()"/>
		</p>
		<p id=result></p>
		<script>
			var arr=[121,200,314,400,100,150,100,300,255];
		function sum(){
			
			var sum=0;
			for(var i=0;i<arr.length;i++){
				sum=sum+arr[i];
			
			}
		result.innerText=sum;
		}
	    
	    
	    function reversal(){
	    	for(var i=arr.length-1;i>=0;i--){
	    		document.write(arr[i]+" ");
	    		
	    	}
	    }
	    
	    
	    function contain(){
	    	for(var i=0;i<arr.length;i++){
				if(arr[i]==100){
					result.innerText=i+1;
					break;
				}
			}
	    }
	    
	    
	    function add(){
	    	var a=prompt("添加第一个数");
	    	var b=prompt("添加第二个数");
	    	var c=prompt("添加第三个数");
	    	arr.splice(2,0,a,b,c);
	    	for(var i=arr.length-1;i>=0;i--){
	    		document.write(arr[i]+" ");
	    	}
	    }
		</script>
	</body>
</html>
